|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.realtime.RawMemoryAccess
An instance of
RawMemoryAccess
models a range of physical
memory as a fixed sequence of bytes. A full complement of accessor
methods allow the contents of the physical area to be accessed through
offsets from the base, interpreted as byte, short, int, or long data
values or as arrays of these types.
Whether the offset addresses the high-order or low-order byte is normally
based on the
value of the
RealtimeSystem.BYTE_ORDER
static byte variable in
class
RealtimeSystem
. If the type of memory used for this
RawMemoryAccess
region implements non-standard byte ordering,
accessor methods in this class continue to select bytes
starting at offset
from the base address and continuing toward
greater addresses. The memory type may control the mapping of these bytes into
the primitive data type. The memory type could even select bytes that are not
contiguous. In each case the documentation for the
PhysicalMemoryTypeFilter
must document any mapping other than the "normal" one specified above.
The RawMemoryAccess
class allows a real-time program to implement device
drivers, memory-mapped I/O, flash memory, battery-backed RAM, and similar
low-level software.
A raw memory area cannot contain references to Java objects. Such a capability would be unsafe (since it could be used to defeat Java's type checking) and error-prone (since it is sensitive to the specific representational choices made by the Java compiler).
Many of the constructors and methods
in this class throw
OffsetOutOfBoundsException
. This
exception means that the value given in the offset parameter is either
negative or outside the memory area.
Many of the constructors and methods
in this class throw
SizeOutOfBoundsException
. This
exception means that the value given in the size parameter is either
negative, larger than an allowable range, or would cause an accessor
method to access an address outside of the memory area.
Unlike other integral parameters in this chapter, negative values are
valid for
byte, short, int,
and long
values that are
copied in and out of memory by the set
and get
methods of this class.
All offset values used in this class are measured in bytes.
Atomic loads and stores on raw memory are defined in terms of physical memory. This memory may be accessible to threads outside the JVM and to non-programmed access (e.g., DMA), consequently atomic access must be supported by hardware. This specification is written with the assumption that all suitable hardware platforms support atomic loads for aligned bytes, shorts, and ints. Atomic access beyond the specified minimum may be supported by the implementation.
Storing values into raw memory is more hardware-dependent than loading values. Many processor architectures do not support atomic stores of variables except for aligned stores of the processor's word size. For instance, storing a byte into memory might require reading a 32-bit quantity into a processor register, updating the register to reflect the new byte value, then re-storing the whole 32-bit quantity. Changes to other bytes in the 32-bit quantity that take place between the load and the store will be lost.
Some processors have mechanisms that can be used to implement an atomic store of a byte, but those mechanisms are often slow and not universally supported.
This class supports unaligned access to data, but it does not require the implementation to make such access atomic. Accesses to data aligned on its natural boundary will be atomic if the processor implements atomic loads and stores of that data size.
Except where noted, accesses to raw memory are not atomic with respect to the memory or with respect to schedulable objects. A raw memory area could be updated by another schedulable object, or even unmapped in the middle of a method.
The characteristics of raw-memory access are necessarily platform dependent. This specification provides a minimum requirement for the RTSJ platform, but it also supports optional system properties that identify a platform's level of support for atomic raw put and get. The properties represent a four-dimensional sparse array with boolean values indicating whether that combination of access attributes is atomic. The default value for array entries is false. The dimension are
Attribute |
Values |
Comment |
Access type | read, write | |
Data type |
|
|
Alignment | 0 to 7 | For each data type, the possible alignments range from
|
Atomicity |
|
|
javax.realtime.atomicaccess_read_byte_0_memory=trueTable entries with a value of false may be explicitly represented, but since false is the default value, such properties are redundant.
All raw memory access is treated as volatile, and serialized. The run-time must be forced to re-read memory or write to memory on each call to a raw memory getxxx or putxxx method, and to complete the reads and writes in the order they appear in the program order.
Constructor Summary | |
RawMemoryAccess(java.lang.Object type,
long size)
Construct an instance of RawMemoryAccess with the given parameters,
and set the object to the mapped state. |
|
RawMemoryAccess(java.lang.Object type,
long base,
long size)
Construct an instance of RawMemoryAccess with the given parameters, and set
the object to the mapped state. |
Method Summary | |
byte |
getByte(long offset)
Gets the byte at the given offset in the memory area associated with this object. |
void |
getBytes(long offset,
byte[] bytes,
int low,
int number)
Gets number bytes starting at the given offset in the memory area associated with this object and assigns them to the byte array passed starting at position low. |
int |
getInt(long offset)
Gets the int at the given offset in the memory area associated with this object. |
void |
getInts(long offset,
int[] ints,
int low,
int number)
Gets number integers starting at the given offset in the memory area associated with this object and assign them to the int array passed starting at position low. |
long |
getLong(long offset)
Gets the long at the given offset in the memory area associated with this object. |
void |
getLongs(long offset,
long[] longs,
int low,
int number)
Gets number longs starting at the given offset in the memory area associated with this object and assign them to the long array passed starting at position low. |
long |
getMappedAddress()
Gets the virtual memory location at which the memory region is mapped. |
short |
getShort(long offset)
Gets the short at the given offset in the memory area associated with this object. |
void |
getShorts(long offset,
short[] shorts,
int low,
int number)
Gets number shorts starting at the given offset in the memory area associated with this object and assign them to the short array passed starting at position low. |
long |
map()
Maps the physical memory range into virtual memory. |
long |
map(long base)
Maps the physical memory range into virtual memory at the specified location. |
long |
map(long base,
long size)
Maps the physical memory range into virtual memory. |
void |
setByte(long offset,
byte value)
Sets the byte at the given offset in the memory area associated with this object. |
void |
setBytes(long offset,
byte[] bytes,
int low,
int number)
Sets number bytes starting at the given offset in the memory area associated with this object from the byte array passed starting at position low. |
void |
setInt(long offset,
int value)
Sets the int at the given offset in the memory area associated with this object. |
void |
setInts(long offset,
int[] ints,
int low,
int number)
Sets number ints starting at the given offset in the memory area associated with this object from the int array passed starting at position low. |
void |
setLong(long offset,
long value)
Sets the long at the given offset in the memory area associated with this object. |
void |
setLongs(long offset,
long[] longs,
int low,
int number)
Sets number longs starting at the given offset in the memory area associated with this object from the long array passed starting at position low. |
void |
setShort(long offset,
short value)
Sets the short at the given offset in the memory area associated with this object. |
void |
setShorts(long offset,
short[] shorts,
int low,
int number)
Sets number shorts starting at the given offset in the memory area associated with this object from the short array passed starting at position low. |
void |
unmap()
Unmap the physical memory range from virtual memory. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RawMemoryAccess(java.lang.Object type, long size)
RawMemoryAccess
with the given parameters,
and set the object to the mapped state.
type
- An instance of Object
representing the type of memory required
(e.g., dma, shared) - used to define the base address and control the mapping.
If the required memory has more than one attribute, type may be an array of objects.
If type
is null
or a reference to an array with no entries, any type of memory is
acceptable. Ignored in present version.size
- The size of the area in bytes.public RawMemoryAccess(java.lang.Object type, long base, long size)
RawMemoryAccess
with the given parameters, and set
the object to the mapped state. If the platform supports virtual memory, map
the raw memory into virtual memory. The run time environment is allowed to
choose the virtual address where the raw memory area corresponding to this
object will be mapped. The attributes of the mapping operation are controlled
by the vMFlags
and vMAttributes
of the
PhysicalMemoryTypeFilter
objects that
matched this object's type parameter. (See
PhysicalMemoryTypeFilter.getVMAttributes()
and PhysicalMemoryTypeFilter.getVMFlags()
.
type
- An instance of Object
representing the type of memory required (e.g.,
dma, shared) - used to define the base address and control the mapping. If the
required memory has more than one attribute, type may be an array of objects.
If type is null
or a reference to an array with no entries, any type of memory
is acceptable.Present version requires type == null.
base
- The physical memory address of the region.size
- The size of the area in bytes.Method Detail |
public byte getByte(long offset)
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs
in the same order as in the program. Multiple writes to the same location may
not be coalesced.)
offset
- The offset in bytes from the beginning of the raw memory from
which to load the byte.
public void getBytes(long offset, byte[] bytes, int low, int number)
Caching of the memory access is
controlled by the memory type requested when the
instance was
created. If the memory is not cached, this method guarantees serialized access
(that is, the memory access at the memory occurs in the same order as in the program.
Multiple writes to the same location may not be coalesced.)
offset
- The offset in bytes from the beginning of the raw memory from which to
start loading.bytes
- The array into which the loaded items are placed.low
- The offset which is the starting point in the given array for the loaded
items to be placed.number
- The number of items to load.public void setByte(long offset, byte value)
This memory access may involve a load and a store, and it may have unspecified effects on surrounding bytes in the presence of concurrent access.
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
= instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs in
the same order as in the program. Multiple writes to the same location may not be
coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area to
which to write the byte.value
- The byte to write.public void setBytes(long offset, byte[] bytes, int low, int number)
This memory access may involve multiple load and a store operations, and it may have unspecified effects on surrounding bytes (even bytes in the range being stored) in the presence of concurrent access.
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs in
the same order as in the program. Multiple writes to the same location may not be
coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area to
which to start writing.bytes
- The array from which the items are obtained.low
- The offset which is the starting point in the given array for the
items to be obtained.number
- The number of items to write.public short getShort(long offset)
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs in
the same order as in the program. Multiple writes to the same location may not be
coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area from
which to load the short.
public void getShorts(long offset, short[] shorts, int low, int number)
If the shorts are located on natural boundaries each short is loaded from memory in a single atomic operation. Groups of shorts may be loaded together, but this is unspecified.
If the shorts are not located on natural boundaries the load may not be atomic, and the number and order of load operations is unspecified.
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs in
the same order as in the program. Multiple writes to the same location may not be
coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area from
which to start loading.shorts
- The array into which the loaded items are placed.low
- The offset which is the starting point in the given array for the
loaded shorts to be placed.number
- The number of shorts to load.public void setShort(long offset, short value)
This memory access may involve a load and a store, and it may have unspecified effects on surrounding shorts in the presence of concurrent access.
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs in
the same order as in the program. Multiple writes to the same location may not be
coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area at
which to write the short.value
- The short to write.public void setShorts(long offset, short[] shorts, int low, int number)
Each write of a short value may involve a load and a store, and it may have unspecified effects on surrounding shorts in the presence of concurrent access - even on other shorts in the array.
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs in
the same order as in the program. Multiple writes to the same location may not be
coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area
at which to start writing.shorts
- The array from which the items are obtained.low
- The offset which is the starting point in the given array
for the items to be obtained.number
- The number of items to write.public int getInt(long offset)
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs in
the same order as in the program. Multiple writes to the same location may not be
coalesced.)
Negative integer values not currently implemented
offset
- The offset in bytes from the beginning of the raw memory area from
which to load the integer.
public void getInts(long offset, int[] ints, int low, int number)
If the integers are aligned on natural boundaries each integer is loaded from memory in a single atomic operation. Groups of integers may be loaded together, but this is unspecified.
If the integers are not aligned on natural boundaries they may not be loaded atomically and the number and order of load operations is unspecified.
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs
in the same order as in the program. Multiple writes to the same location may
not be coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area
at which to start loading.ints
- The array into which the integers read from the raw memory are placed.low
- The offset which is the starting point in the given array for the
loaded items to be placed.number
- The number of integers to loaded.public void setInt(long offset, int value)
This memory access may involve multiple load and a store operations, and it may have unspecified effects on surrounding bytes (even bytes in the range being stored) in the presence of concurrent access.
Caching of the memory access is controlled by the memory type requested when
the RawMemoryAccess
instance was created. If the memory is not cached, this
method guarantees serialized access (that is, the memory access at the memory
occurs in the same order as in the program. Multiple writes to the same location
may not be coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area at
which to write the integer.value
- The integer to write.public void setInts(long offset, int[] ints, int low, int number)
This memory access may involve multiple load and a store operations, and it may have unspecified effects on surrounding bytes (even bytes in the range being stored) in the presence of concurrent access.
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs in
the same order as in the program. Multiple writes to the same location may not be
coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area at
which to start writing.ints
- The array from which the items are obtained.low
- The offset which is the starting point in the given array for the
items to be obtained.number
- The number of items to write.public long getLong(long offset)
The load is not required to be atomic even it is located on a natural boundary.
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs in
the same order as in the program. Multiple writes to the same location may not be
coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area from
which to load the long.
public void getLongs(long offset, long[] longs, int low, int number)
The loads are not required to be atomic even if they are located on natural boundaries.
Caching of the memory access is controlled by the memory type requested when the
public void setLong(long offset, long value)
This memory access may involve multiple load and a store operations, and it may have unspecified effects on surrounding bytes (even bytes in the range being stored) in the presence of concurrent access.
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs in
the same order as in the program. Multiple writes to the same location may not be
coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area at
which to write the long.value
- The long to write.public void setLongs(long offset, long[] longs, int low, int number)
This memory access may involve multiple load and a store operations, and it may have unspecified effects on surrounding bytes (even bytes in the range being stored) in the presence of concurrent access.
Caching of the memory access is controlled by the memory type requested when the
RawMemoryAcccess
instance was created. If the memory is not cached, this method
guarantees serialized access (that is, the memory access at the memory occurs
in the same order as in the program. Multiple writes to the same location may
not be coalesced.)
offset
- The offset in bytes from the beginning of the raw memory area at
which to start writing.longs
- The array from which the items are obtained.low
- The offset which is the starting point in the given array for the
items to be obtained.number
- The number of items to write.public long getMappedAddress()
Not currently implemented
public long map()
The run time environment is allowed to choose the virtual address where the raw
memory area corresponding to this object will be mapped. The attributes of the
mapping operation are controlled by the vMFlags and vMAttributes of the
PhysicalMemoryTypeFilter
objects that matched this object's type parameter.
(See PhysicalMemoryTypeFilter.getVMAttributes()
and
PhysicalMemoryTypeFilter.getVMFlags()
.
If the object is already mapped into virtual memory, this method does not change anything.
public long map(long base)
PhysicalMemoryTypeFilter
objects that matched this object's type parameter.
(See PhysicalMemoryTypeFilter.getVMAttributes()
and
PhysicalMemoryTypeFilter.getVMFlags()
. If the object is
already mapped into
virtual memory at a different address, this method remaps it to base.If a remap is requested while another schedulable object is accessing the raw memory, the map will block until one load or store completes. It can interrupt an array operation between entries.
base
- The location to map at the virtual memory space.
public long map(long base, long size)
The attributes of the mapping operation are controlled by the
vMFlags
and vMAttributes
of the PhysicalMemoryTypeFilter
objects that matched this object's
type parameter. (See PhysicalMemoryTypeFilter.getVMAttributes()
and PhysicalMemoryTypeFilter.getVMFlags()
.
If the object is already mapped into virtual memory at a different address, this method remaps it to base.
If a remap is requested while another schedulable object is accessing the raw memory, the map will block until one load or store completes. It can interrupt an array operation between entries.
base
- The location to map at the virtual memory space.size
- The size of the block to map in. If the size of the raw memory area
is greater than size, the object is unchanged but accesses beyond the mapped region
will throw SizeOutOfBoundsException
.
If the size of the raw memory area is smaller
than the mapped region access to the raw memory will behave as if the mapped
region matched the raw memory area, but additional virtual address space will
be consumed after the end of the raw memory area.
public void unmap()
If the object is already in the unmapped state, this method has no effect.
While a raw memory object is unmapped all attempts to set or get values in the raw memory will throw SizeOutOfBoundsException.
An unmapped raw memory object can be returned to mapped state with any of the object's map methods.
If an unmap is requested while another schedulable object is accessing the raw
memory, the unmap()
will throw an
IllegalStateException
. The unmap()
method can
interrupt an array operation between entries.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |